package edu.hnu.cloudflight.android.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
/**
 * 日期工具类
 * @author Administrator
 *
 */
public class DateUtil {
	

	/**
	 * 日期格式：yyy-MM-dd
	 */
	public static SimpleDateFormat sdf1 = new SimpleDateFormat("yyy-MM-dd",Locale.CHINA);
	
	/**
	 * 日期格式:yyy-MM-dd HH:mm:ss
	 */
	public static SimpleDateFormat sdf2 = new SimpleDateFormat("yyy-MM-dd HH:mm:ss",Locale.CHINA);
	
	
	public static String getNowDateToString(){
		return sdf2.format(new Date());
	}
	
	/**
	 * 获取当前时间
	 * @param sdf 返回时间格式
	 * @return
	 */
	public static String getNowDateToString(SimpleDateFormat sdf){
		return sdf.format(new Date());
	}
	
	public static String getStringFromParams(int year,int month,int day){
		StringBuilder sb = new StringBuilder();
		sb.append(year + 1).append("-").append(month).append("-").append(day).append(" ");
		return sb.toString();
	}
	
	
	public static String getPreDateString(String today){
		return getPreDateString(today, sdf1);
	}
	/**
	 * 获取某一日期的前一天日期
	 * @param today
	 * @param sdf
	 * @return
	 */
	public static String getPreDateString(String today,SimpleDateFormat sdf){
		Calendar c = Calendar.getInstance();
		try {
			Date nowDate = sdf.parse(today);
			c.setTime(nowDate);
			int day=c.get(Calendar.DATE); 
			c.set(Calendar.DATE,day-1); 
			String dayBefore=sdf.format(c.getTime()); 
			return dayBefore;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getNextDateString(String today){
		return getNextDateString(today, sdf1);
	}
	
	public static String getNextDateString(String today,SimpleDateFormat sdf){
		Calendar c = Calendar.getInstance();
		try {
			Date nowDate = sdf.parse(today);
			c.setTime(nowDate);
			int day=c.get(Calendar.DATE); 
			c.set(Calendar.DATE,day+1); 
			String dayBefore=sdf.format(c.getTime()); 
			return dayBefore;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
